// pages/my/my_serveDetail/index.js
const serve=require("../../controllers/ControllerX").controller.serve;
const agreeOrder=require("../../controllers/ControllerX").controller.agreeOrder;
const cancleOrder=require("../../controllers/ControllerX").controller.cancleOrder;

const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dialogShow: false,
    buttons: [{text: '取消'}, {text: '确定'}],
    serveDetail:{},
    ids:'',
    cancleText:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let ids=options.ids;
    this.setData({
      ids:ids
    })
    let shopId=wx.getStorageSync('shopId');
    this.getServe({shopId:shopId,goodsAgreeId:ids});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // },
  openConfirm: function () {
    this.setData({
        dialogShow: true
    })
},
tapDialogButton(e) {
    this.setData({
        dialogShow: false
    })
    if(e.detail.index==0){

    }else{
      this.getCancleOrder()
    }
},

//获取预约记录详情
  getServe(value){
    serve(value).then(res=>{
      this.setData({
        serveDetail:res.data
      })
    })
  },

  //同意预约
  bindAgreeOrder(){
    let ids=this.data.ids;
    let shopId=wx.getStorageSync('shopId');
    agreeOrder({shopId:shopId,goodsAgreeId:ids}).then(res=>{
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      })
      setTimeout(function(){
        wx.navigateBack({})
      },2000)
    })
  },

  //获取拒绝预约理由
  getCancleText(e){
    this.setData({
      cancleText:e.detail.value
    })
  },

  //提交拒绝预约信息
  getCancleOrder(){
    cancleOrder({shopId:wx.getStorageSync('shopId'),goodsAgreeId:this.data.ids,failDesc:this.data.cancleText}).then(res=>{
      if(res.code==1){
        wx.showToast({
          title: '拒绝信息已提交',
          duration:1500
        })
        setTimeout(function(){
          wx.navigateBack()
        },1500)
      }else{

      }
    })
  }
})